

# https://fanyi.baidu.com/v2transapi?from=en&to=zh
# https://fanyi.sogou.com/api/transpc/text/result
# https://fanyi.sogou.com/reventondc/suggV3


import urllib.request
import urllib.parse
import json

url = 'https://fanyi.sogou.com/reventondc/suggV3'

headers = {
    'cookie':'BIDUPSID=E04D67B5F25C419FF5CAC9517D0526B4; PSTM=1733134135; BAIDUID=E04D67B5F25C419F6775388B1B95BE63:FG=1; Hm_lvt_64ecd82404c51e03dc91cb9e8c025574=1737159441; H_WISE_SIDS=60278_61027_60853_61610_61693_61780_61823_61844_61987; BDORZ=B490B5EBF6F3CD402E515D22BCDA1598; H_WISE_SIDS_BFESS=60278_61027_60853_61610_61693_61780_61823_61844_61987; BA_HECTOR=00800hakak042ha5242g850ga1psak1jp0s691v; ZFY=4hsy5BOePz7gRC:A4vV09l7WGfkhAzRWuxrsWBfDDLsM:C; BAIDUID_BFESS=E04D67B5F25C419F6775388B1B95BE63:FG=1; PSINO=2; H_PS_PSSID=60278_61027_60853_61610_61693_61746_61745_61743_61780_61823_61844_61987; delPer=0; ab_sr=1.0.1_YzU0MzFjZTAxZjgwMTVhZDIzOTQwZDMwZGUzMmViNmI1ODhlMjYyYzM2MjQ2ZjBhM2IzYTU4YjBhNGI0MjQxZTMxMWI0NTc1NTA2ODRlNTRiNGRhODYzMGRhYTJmNDMwYTUzMjAxMWY0NDIzMzA5M2FhNTMwNTZhZjVjZjU3N2Q3MGZhYmVkNjEwZWQ0YzNjODc3ZjVlMDZkNDJkMWU1NDRhZmZiN2NmNGNhNDZjMzMxZTYwMjAzNGIyYjc5NGU1YjI1ZTk0NTFkYzFhMmVhY2MxNjU0NmFmYTk4ZWQ1NWM=; RT="z=1&dm=baidu.com&si=d7da922e-89d4-43a9-b0e4-1027d578bbea&ss=m67linjv&sl=3&tt=977&bcn=https%3A%2F%2Ffclog.baidu.com%2Flog%2Fweirwood%3Ftype%3Dperf&ld=r4y"',
    'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36'
}

result_data = {
    "from":"auto",
    "to":"zh-CHS",
    "text":"apple",
    "client":"pc",
    "fr":"browser_pc",
    "needQc":"1",
    "s":"85f1a4e817ac4f06719fe7120ad9547d",
    "uuid":"87b986e1-77d0-46c8-ace1-9384963bf25c",
    "exchange":"false"
}
data = {
    "from":"auto",
    "to":"zh-CHS",
    "text":"apple",
    "uuid":"87b986e1-77d0-46c8-ace1-9384963bf25c",
    "pid":"sogou-dict-vr",
    "addSugg":"on"
}

datacode =  urllib.parse.urlencode(data).encode('utf-8')
# print(datacode)

require_param =  urllib.request.Request(url=url,headers=headers,data=datacode)
# print(require_param)
# <urllib.request.Request object at 0x000002422DDC8DD0>


# 模拟向服务器发送请求
response = urllib.request.urlopen(require_param)

# 获取响应数据
content = response.read().decode("utf-8")
# print(content)
# UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8b in position 1: invalid start byte
# 'accept-encoding':'gzip, deflate, br, zstd',

# 字符串转json
obj = json.loads(content)
print(obj)

